#!/bin/bash

# k8s version
version=1.25.9

# coredns version
coredns=v1.9.3

# aliyun url
url=registry.aliyuncs.com/google_containers

# install kubelet kubeadm kubectl 
yum install -y kubelet-$version kubeadm-$version kubectl-$version

systemctl enable kubelet && systemctl start kubelet

# list k8s images
kubeadm config images list --image-repository $url --kubernetes-version $version

# pull k8s images from aliyun
images=(`kubeadm config images list --kubernetes-version=$version|awk -F '/' '{print $2}'`)
for imagename in ${images[@]} ; do
   if [ $imagename = "coredns" ]
   then
      nerdctl -n k8s.io pull $url/$imagename:$coredns
      nerdctl -n k8s.io tag $url/$imagename:$coredns registry.k8s.io/coredns/coredns:$coredns
      nerdctl -n k8s.io rmi -f $url/$imagename:$coredns
   else
      nerdctl -n k8s.io pull $url/$imagename
      nerdctl -n k8s.io tag $url/$imagename registry.k8s.io/$imagename
      nerdctl -n k8s.io rmi -f $url/$imagename
  fi
done

nerdctl -n k8s.io images


